import java.util.ArrayList;
import java.util.List;

class Solution {
//    public int[] twoSum(int[] nums, int target) {
//        for (int i = 0; i < nums.length; i++) {
//            for (int j = i+1; j < nums.length; j++) {
//                if(nums[i] + nums[j] == target) return new int[]{i,j};
//            }
//        }
//        return null;


    //法二
    public int[] twoSum(int[] nums, int target) {
        List<Integer> ret = new ArrayList<>();

        for (int i = 0; i < nums.length; i++) {
            if (ret.contains(nums[i])){
                //返回i，和target-nums[i]的下标
                return new int[]{i,ret.indexOf(nums[i])};
            }
            ret.add(target - nums[i]); //将每一个 target-nums[i] 的值存入到动态数组Arraylist中，下标是i
        }
        return null;
    }
}